//
//  Constant-Swift.swift
//  QDMetroClient
//
//  Created by YueWen on 2019/2/22.
//  Copyright © 2019 YueWen. All rights reserved.
//

import Foundation

//MARK: Lang
class QDLanguage: NSObject {
    
    /// 当前语言的id
    @objc static var localIdentifier: String {
        get {
            guard let identifier = NSLocale.preferredLanguages.first else {
                return "ZH" //默认中文
            }
            return (identifier.contains("zh") || identifier.contains("ZH")) ? "ZH" : "EN"
        }
    }
}

extension String {
    
    /// 地铁发票多语言化
    var localForMetroBill: String {
        switch self {
        case "EN": return "en"
        default: return "cn"
        }
    }
}


//MARK: Color

/// 青岛地铁Color常量
struct QDColors {
    
    /// 主题色 105 201 121
    static let theme = #colorLiteral(red: 0.4117647059, green: 0.7882352941, blue: 0.4745098039, alpha: 1)
    /// 151 153 152
    static let gray = #colorLiteral(red: 0.5921568627, green: 0.6, blue: 0.5960784314, alpha: 1)
    /// 地铁分割线颜色 76 77 76
    static let separator = #colorLiteral(red: 0.2980392157, green: 0.3019607843, blue: 0.2980392157, alpha: 1)
    /// 地铁黑，不是纯黑 88 89 89
    static let black = #colorLiteral(red: 0.2980392157, green: 0.3019607843, blue: 0.2980392157, alpha: 1)
    /// 177 179 177
    static let gray2 = #colorLiteral(red: 0.6941176471, green: 0.7019607843, blue: 0.6941176471, alpha: 1)
    /// 全局橙色
    static let orange = #colorLiteral(red: 0.9882352941, green: 0.6392156863, blue: 0.06666666667, alpha: 1)
}


//MARK: API

/// 青岛地铁的基础url - 待废除
struct QDBaseUrl {
    
    static let api = "https://api.qd-metro.com"
    static let auth = "http://auth.qd-metro.com"
    static let site = "http://site.qd-metro.com"
}


//MARK: 适配X

/// 是否存在刘海平
public func hasPhoneHeader() -> Bool {
    
    let headerPhones = [CGSize(width: 375, height: 812),
                        CGSize(width: 414, height: 896)]
    
    return headerPhones.contains(UIScreen.main.bounds.size)
}


///  是否是iPhoneX
@available(iOS, introduced: 8.0, deprecated: 8.0, message: "Use hasPhoneHeader instead.")
public func is_iPhoneX() -> Bool {
    
    let screenSize = UIScreen.main.bounds.size
    return screenSize.width == 375 && screenSize.height == 812
}





//MARK: BarHeight

/// tab的具体
public enum BarDistance {
    case NavigationBar
    case TabBar
}


extension BarDistance {
    
    /// 正常情况下的高度
    var normalHeight: CGFloat {
        switch self {
        case .NavigationBar:
            return 64
        case .TabBar:
            return 49
        }
    }
    
    
    /// 默认高度
    var height: CGFloat {
        switch self {
        case .NavigationBar:
            return hasPhoneHeader() ? 88 : 64
        case .TabBar:
            return hasPhoneHeader() ? 83 : 49
        }
    }
    
    /// 安全间隔
    var safeDistance: CGFloat {
        switch self {
        case .NavigationBar:
            return hasPhoneHeader() ? 88 - 64 : 0
        case .TabBar:
            return hasPhoneHeader() ? 83 - 64 : 0
        }
    }
}
